package com.gaohe.web.controller.hotal;

import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.core.page.TableDataInfo;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.hotal.domain.HotRoom;
import com.gaohe.hotal.service.IHotRoomService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房间Controller
 *
 * @author ruoyi
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/hotal/room")
public class HotRoomController extends BaseController
{
    @Autowired
    private IHotRoomService hotRoomService;

    /**
     * 查询房间列表
     */
    @PreAuthorize("@ss.hasPermi('hotal:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(HotRoom hotRoom)
    {
        startPage();
        List<HotRoom> list = hotRoomService.selectHotRoomList(hotRoom);
        return getDataTable(list);
    }

    /**
     * 导出房间列表
     */
    @PreAuthorize("@ss.hasPermi('hotal:room:export')")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotRoom hotRoom)
    {
        List<HotRoom> list = hotRoomService.selectHotRoomList(hotRoom);
        ExcelUtil<HotRoom> util = new ExcelUtil<HotRoom>(HotRoom.class);
        util.exportExcel(response, list, "房间数据");
    }

    /**
     * 获取房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotal:room:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(hotRoomService.selectHotRoomByRoomId(roomId));
    }

    /**
     * 新增房间
     */
    @PreAuthorize("@ss.hasPermi('hotal:room:add')")
    @Log(title = "房间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotRoom hotRoom)
    {
        return toAjax(hotRoomService.insertHotRoom(hotRoom));
    }

    /**
     * 修改房间
     */
    @PreAuthorize("@ss.hasPermi('hotal:room:edit')")
    @Log(title = "房间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotRoom hotRoom)
    {
        return toAjax(hotRoomService.updateHotRoom(hotRoom));
    }

    /**
     * 删除房间
     */
    @PreAuthorize("@ss.hasPermi('hotal:room:remove')")
    @Log(title = "房间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(hotRoomService.deleteHotRoomByRoomIds(roomIds));
    }
}
